﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TCCHWLib
{
    public class SignatureRegister
    {
        private List<bool> m_SignBits = null;
        private int m_Capacity = 32;

        public SignatureRegister(int size)
        {
            m_Capacity = size;

            m_SignBits = new List<bool>(m_Capacity);
            initialize();
        }
        private void initialize()
        {
            for (int i = 0; i < m_Capacity; i++)
                m_SignBits.Add(false);
        }

        public void Insert(int address)
        {
            int h1 = Hash_1(address);
            int h2 = Hash_2(address);

            m_SignBits[h1] = m_SignBits[h2] = true;
        }
        public bool LookUp(int address)
        {
            int h1 = Hash_1(address);
            int h2 = Hash_2(address);

            return m_SignBits[h1] & m_SignBits[h2];
        }

        private int Hash_1(int address)
        {
            return address % m_Capacity;
        }
        private int Hash_2(int address)
        {
            return (address ^ (2 * address)) % m_Capacity;
        }
        public void ResetRegister()
        {
            for (int i = 0; i < m_Capacity; i++)
                m_SignBits[i] = false;
        }
    }
}
